﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iNet.Media.Xmp.IPTC
{
	public class ContactInfoXmpPropertyValue : StructureXmpPropertyValue
	{
		#region 欄位
		public static readonly XmpSchema DefaultSchema = CommonXmpSchemas.IptcCore;
		#endregion
		#region 建構子
		public ContactInfoXmpPropertyValue()
			: this(DefaultSchema)
		{ }
		public ContactInfoXmpPropertyValue(XmpSchema schema)
			: base(schema)
		{
			if (schema == null)
				throw new ArgumentNullException("schema");
		}
		#endregion
		#region CiAdrCity
		public TextXmpPropertyValue CiAdrCity { get; set; }
		#endregion
		#region CiAdrCtry
		public TextXmpPropertyValue CiAdrCtry { get; set; }
		#endregion
		#region CiAdrExtadr
		public TextXmpPropertyValue CiAdrExtadr { get; set; }
		#endregion
		#region CiAdrPcode
		public TextXmpPropertyValue CiAdrPcode { get; set; }
		#endregion
		#region CiAdrRegion
		public TextXmpPropertyValue CiAdrRegion { get; set; }
		#endregion
		#region CiEmailWork
		public TextXmpPropertyValue CiEmailWork { get; set; }
		#endregion
		#region CiTelWork
		public TextXmpPropertyValue CiTelWork { get; set; }
		#endregion
		#region CiUrlWork
		public TextXmpPropertyValue CiUrlWork { get; set; }
		#endregion
		#region CloneCore
		protected override XmpPropertyValue CloneCore()
		{
			//建立副本
			ContactInfoXmpPropertyValue contactInfo = new ContactInfoXmpPropertyValue(this.Schema);
			this.CopyFieldsTo(contactInfo);

			//回傳
			return contactInfo;
		}
		#endregion
		#region FieldNames
		public override string[] FieldNames
		{
			get 
			{
				return new string[]
				{
					"CiAdrCity",
					"CiAdrCtry",
					"CiAdrExtadr",
					"CiAdrPcode",
					"CiAdrRegion",
					"CiEmailWork",
					"CiTelWork",
					"CiUrlWork",
				};
			}
		}
		#endregion
		#region GetFieldCore
		protected override XmpPropertyValue GetFieldCore(string name)
		{
			switch (name)
			{
				case "CiAdrCity":
					return this.CiAdrCity;
				case "CiAdrCtry":
					return this.CiAdrCtry;
				case "CiAdrExtadr":
					return this.CiAdrExtadr;
				case "CiAdrPcode":
					return this.CiAdrPcode;
				case "CiAdrRegion":
					return this.CiAdrRegion;
				case "CiEmailWork":
					return this.CiEmailWork;
				case "CiTelWork":
					return this.CiTelWork;
				case "CiUrlWork":
					return this.CiUrlWork;
				default:
					throw new ArgumentException();
			}
		}
		#endregion
		#region SetFieldCore
		protected override void SetFieldCore(string name, XmpPropertyValue value)
		{
			//確認參數
			if (value != null && !(value is TextXmpPropertyValue))
				throw new ArgumentException();

			//設定欄位
			switch (name)
			{
				case "CiAdrCity":
					this.CiAdrCity = (value as TextXmpPropertyValue);
					break;
				case "CiAdrCtry":
					this.CiAdrCtry = (value as TextXmpPropertyValue);
					break;
				case "CiAdrExtadr":
					this.CiAdrExtadr = (value as TextXmpPropertyValue);
					break;
				case "CiAdrPcode":
					this.CiAdrPcode = (value as TextXmpPropertyValue);
					break;
				case "CiAdrRegion":
					this.CiAdrRegion = (value as TextXmpPropertyValue);
					break;
				case "CiEmailWork":
					this.CiEmailWork = (value as TextXmpPropertyValue);
					break;
				case "CiTelWork":
					this.CiTelWork = (value as TextXmpPropertyValue);
					break;
				case "CiUrlWork":
					this.CiUrlWork = (value as TextXmpPropertyValue);
					break;
				default:
					throw new ArgumentException();
			}
		}
		#endregion
	}

	public class ContactInfoXmpPropertyValueFactory : StructureXmpPropertyValueFactory<ContactInfoXmpPropertyValue>
	{
		#region 建構子
		public ContactInfoXmpPropertyValueFactory()
			: base("http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/", null)
		{ }
		#endregion
		#region CreateValue
		protected override ContactInfoXmpPropertyValue CreateValue(XmpSchema schema)
		{
			return new ContactInfoXmpPropertyValue(schema);
		}
		#endregion
	}
}
